package com.easygo.controller;

import com.easygo.service.ITypeTemplateService;
import com.easygo.utils.PageUtils;
import com.xuexi.easygo.pojo.TypeTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@Scope("prototype")
public class TypeTemplateController {

    @Autowired
    ITypeTemplateService templateService;

    @RequestMapping("typeTemplate_page")
    public PageUtils<TypeTemplate> getTypeTemplatePage(@RequestParam(defaultValue = "1", required = false,value = "pageIndex") Integer pageIndex,
                                                       @RequestParam(defaultValue = "5", required = false,value = "pageSize") Integer pageSize,
                                                       @RequestParam(defaultValue = "", required = false,value = "name") String name) {
        Map<String,Object> map = new HashMap<>();
        map.put("pageStart",(pageIndex-1)*pageSize);
        map.put("pageSize",pageSize);
        map.put("name","%"+name+"%");
        Integer totalcount = templateService.getTotalCount(map);
        List<TypeTemplate> typeTemplatePage = templateService.getTypeTemplatePage(map);
        PageUtils<TypeTemplate> pageUtils = new PageUtils<>(pageSize,pageIndex,totalcount,typeTemplatePage);
        return pageUtils;
    }

    @RequestMapping("typeTemplate_all")
    public List<TypeTemplate> getTypeTemplates(){
        return templateService.getTypeTemplates();
    }
}
